//js渲染脚本
layui.use(['jquery', 'layer'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    $.support.cors = true;

    //全局变量定义
    var _gonggao = {
        current: 0,
        page: 0,
        total: 0
    };
    var _tongzhi = {
        current: 0,
        page: 0,
        total: 0
    };
    var _jiangcheng = {
        current: 0,
        page: 0,
        total: 0
    };
    var _xinwen = {
        current: 0,
        page: 0,
        total: 0
    };
    var _caozuo = {
        current: 0,
        page: 0,
        total: 0
    };

    var CATEGORY = {
        no: {
            category: 0,
            text: ""
        },
        gonggao: {
            category: 1,
            text: "公告"
        },
        tongzhi: {
            category: 2,
            text: "通知"
        },
        jiangcheng: {
            category: 3,
            text: "奖惩"
        },
        xinwen: {
            category: 4,
            text: "新闻"
        },
        caozuo: {
            category: 5,
            text: "操作指南"
        }
    };
    //分页条数
    var COUNT = 10;
    //标识当前类别的参数
    var category = CATEGORY.no;





    //初始化工作
    //设置初始图片
    $.each($("#news_nav img"), function (i, img) {
        switch (img.id) {
            case "head":
                img.src = "./images/head.jpg";
                break;
            case "gonggao":
                img.src = "./images/gonggao_a.jpg";
                break;
            case "tongzhi":
                img.src = "./images/tongzhi_a.jpg";
                break;
            case "jiangcheng":
                img.src = "./images/jiangcheng_a.jpg";
                break;
            case "xinwen":
                img.src = "./images/xinwen_a.jpg";
                break;
            case "caozuo":
                img.src = "./images/caozuo_a.jpg";
                break;
            case "foot":
                img.src = "./images/foot.jpg";
                break;
        }
    });
    //请求最新的一条公告
    $.ajax({
        type: "GET",
        contentType: "application/json;charset=utf-8",
        url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
        data: {
            //无参数，就是最新的一条
            'category': 'common'
        },
        crossDomain: true,
        success: function (data) {
            //成功之后对中间区域进行渲染
            var contentString = '';
            //拼接标题和内容
            contentString += '<div class="r1c2-div7"><b>' + data.news.news_title + '</b></div>';

            contentString += '<div class="r1c2-div8"><span>来源：' + data.news.orgcode
                + '</span><span> &nbsp&nbsp&nbsp&nbsp&nbsp</span><span>发布时间：'
                + data.news.cha_date + '</span></div><div class="r1c2-div9"></div>'

            contentString += '<div class="r1c2-div10">'
                + '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'
                + data.news.content + ' </div><br />'

            contentString += '<br/><div class="r1c2-div11"><span>附件下载：</span><span></span>'
            //拼接附件
            $.each($(data.files), function (i, file) {

                contentString += '<a href="'
                    + 'http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do?category=download&news_fid='
                    + file.news_fid + '">' + file.filename + '</a>';
            })
            contentString += '</span></div><br/><br/><br/>';
            // console.log(contentString)
            $("#content").html(contentString);
            $("#title").html('<i class="layui-icon" style="font-size: 30px;" id="ret">&#xe65c;</i>');
            $("#page").html("");

            switch (data.news.news_cat) {
                case "1":
                    //gonggao
                    category = CATEGORY.gonggao;
                    _gonggao.count = COUNT;
                    _gonggao.current = 1;
                    _gonggao.page = 0;
                    $("#gonggao").attr("src", "./images/gonggao_b.jpg");
                    break;
                case "2":
                    //tongzhi
                    category = CATEGORY.tongzhi;
                    _tongzhi.count = COUNT;
                    _tongzhi.current = 1;
                    _tongzhi.page = 0;
                    $("#tongzhi").attr("src", "./images/tongzhi_b.jpg");
                    break;
                case "3":
                    //jiangcheng
                    category = CATEGORY.jiangcheng;
                    _jiangcheng.count = COUNT;
                    _jiangcheng.current = 1;
                    _jiangcheng.page = 0;
                    $("#jiangcheng").attr("src", "./images/jiangcheng_b.jpg");
                    break;
                case "4":
                    //xinwen
                    category = CATEGORY.xinwen;
                    _xinwen.count = COUNT;
                    _xinwen.current = 1;
                    _xinwen.page = 0;
                    $("#xinwen").attr("src", "./images/xinwen_b.jpg");
                    break;
                case "5":
                    //caozuo
                    category = CATEGORY.caozuo;
                    _caozuo.count = COUNT;
                    _caozuo.current = 1;
                    _caozuo.page = 0;
                    $("#caozuo").attr("src", "./images/caozuo_b.jpg");
                    break;
            }
            $("#ret").click(function () {
                //返回当前列表
                retCk(category);
            });

        },
        error: function (e) {

        }
    });
    //初始化工作


    //全局函数定义
    //清空非当前类别全局参数
    function clearCategory(classfi) {
        switch (classfi.category) {
            case 'gonggao':
                category = CATEGORY.gonggao;
                _tongzhi.page = 0;
                _tongzhi.current = 0;
                _tongzhi.total = 0;
                _jiangcheng.page = 0;
                _jiangcheng.current = 0;
                _jiangcheng.total = 0;
                _xinwen.page = 0;
                _xinwen.current = 0;
                _xinwen.total = 0;
                _caozuo.page = 0;
                _caozuo.current = 0;
                _caozuo.total = 0;
                break;
            case 'tongzhi':
                category = CATEGORY.tongzhi;
                _gonggao.page = 0;
                _gonggao.current = 0;
                _gonggao.total = 0;
                _jiangcheng.page = 0;
                _jiangcheng.current = 0;
                _jiangcheng.total = 0;
                _xinwen.page = 0;
                _xinwen.current = 0;
                _xinwen.total = 0;
                _caozuo.page = 0;
                _caozuo.current = 0;
                _caozuo.total = 0;
                break;
            case 'jiangcheng':
                category = CATEGORY.jiangcheng;
                _gonggao.page = 0;
                _gonggao.current = 0;
                _gonggao.total = 0;
                _tongzhi.page = 0;
                _tongzhi.current = 0;
                _tongzhi.total = 0;
                _xinwen.page = 0;
                _xinwen.current = 0;
                _xinwen.total = 0;
                _caozuo.page = 0;
                _caozuo.current = 0;
                _caozuo.total = 0;
                break;
            case 'xinwen':
                category = CATEGORY.xinwen;
                _gonggao.page = 0;
                _gonggao.current = 0;
                _gonggao.total = 0;
                _tongzhi.page = 0;
                _tongzhi.current = 0;
                _tongzhi.total = 0;
                _jiangcheng.page = 0;
                _jiangcheng.current = 0;
                _jiangcheng.total = 0;
                _caozuo.page = 0;
                _caozuo.current = 0;
                _caozuo.total = 0;
                break;
            case 'caozuo':
                category = CATEGORY.caozuo;
                _gonggao.page = 0;
                _gonggao.current = 0;
                _gonggao.total = 0;
                _tongzhi.page = 0;
                _tongzhi.current = 0;
                _tongzhi.total = 0;
                _jiangcheng.page = 0;
                _jiangcheng.current = 0;
                _jiangcheng.total = 0;
                _xinwen.page = 0;
                _xinwen.current = 0;
                _xinwen.total = 0;
                break;
            default:
                break;
        }
    };
    //查看新闻详细内容
    function contentCk(data) {
        // console.log(data)
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: data,
            crossDomain: true,
            success: function (dat) {
                //填充内容和构建a标签
                var contentString = '';
                //拼接标题和内容
                contentString += '<div class="r1c2-div7"><b>' + dat.news.news_title + '</b></div>';

                contentString += '<div class="r1c2-div8"><span>来源：' + dat.news.orgcode
                    + '</span><span> &nbsp&nbsp&nbsp&nbsp&nbsp</span><span>发布时间：'
                    + dat.news.cha_date + '</span></div><div class="r1c2-div9"></div>'

                contentString += '<div class="r1c2-div10">'
                    + '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'
                    + dat.news.content + ' </div><br /><br />'

                contentString += '<div class="r1c2-div11"><span>附件下载：</span><span></span>'
                //拼接附件
                $.each($(dat.files), function (i, file) {

                    contentString += '<a href="'
                        + 'http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do?category=download&news_fid='
                        + file.news_fid + '">' + file.filename + '</a>';
                })
                contentString += '</span></div><br/><br/><br/>';
                $("#content").html(contentString);
                $("#title").html('<i class="layui-icon" style="font-size: 30px;" id="ret">&#xe65c;</i>');
                $("#page").html("");

                switch (dat.news.news_cat) {
                    case "1":
                        //gonggao
                        category = CATEGORY.gonggao;

                        $("#gonggao").attr("src", "./images/gonggao_b.jpg");
                        break;
                    case "2":
                        //tongzhi
                        category = CATEGORY.tongzhi;
                        $("#tongzhi").attr("src", "./images/tongzhi_b.jpg");
                        break;
                    case "3":
                        //jiangcheng
                        category = CATEGORY.jiangcheng;
                        $("#jiangcheng").attr("src", "./images/jiangcheng_b.jpg");
                        break;
                    case "4":
                        //xinwen
                        category = CATEGORY.xinwen;

                        $("#xinwen").attr("src", "./images/xinwen_b.jpg");
                        break;
                    case "5":
                        //caozuo
                        category = CATEGORY.caozuo;

                        $("#caozuo").attr("src", "./images/caozuo_b.jpg");
                        break;
                };
                $("#ret").click(function () {
                    //返回当前列表
                    retCk(category);
                });





            },
            error: function (e) {
                // console.log(e)
            }
        });
    };
    //进行分页查询并更新新闻列表
    function gonggaoCk(data) {
        //分页操作
        var page = 0;
        if ("front" === data.signal) {
            if (1 === _gonggao.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有上一页',
                    time: 2000
                });
            } else {
                page = _gonggao.current - 1;
            }
        }
        if ("behind" === data.signal) {
            if (_gonggao.page === _gonggao.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有下一页',
                    time: 2000
                });
            } else {
                page = _gonggao.current + 1;
            }
        }
        if ("random" === data.signal) {
            page = data.page;
        }
        if (page === 0) {
            return;
        }
        //请求分页列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                category: "gonggao",
                page: page,
                count: COUNT,
                total: _gonggao.total
            },
            crossDomain: true,
            success: function (dat) {
                // console.log(dat)
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //渲染类别标题
                $("#title").html("公告")
                //渲染列表
                $.each(dat.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数

                newPage = parseInt(dat.total / COUNT);
                mod = dat.total % COUNT;
                if (mod != 0) {
                    newPage += 1;
                };
                //初始化公告类别当前分页信息
                _gonggao.page = newPage;
                switch (dat.msg) {
                    case "0":
                        //删除了上一页的内容
                        _gonggao.current = newPage;
                        break;
                    case "1":
                        //最后一页
                        _gonggao.current = newPage;
                        break;
                    case "2":
                        //还有余量

                        if (data.signal === 'front') {
                            if (_gonggao.current <= newPage) {
                                _gonggao.current -= 1;
                            } else {
                                _gonggao.current = newPage;
                            }
                        }
                        if (data.signal === 'behind') {

                            if (_gonggao.current < newPage) {
                                _gonggao.current += 1;
                            } else {
                                _gonggao.current = newPage;
                            }

                        }
                        if (data.signal === 'random') {
                            if (data.page <= newPage) {
                                _gonggao.current = parseInt(data.page);
                            } else {
                                _gonggao.current = newPage;
                            }
                        }

                        break;

                };
                _gonggao.total = parseInt(dat.total);
                clearCategory(CATEGORY.gonggao);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _gonggao.page; i++) {
                    if (i == _gonggao.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    gonggaoCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    gonggaoCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    gonggaoCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })
            },
            error: function (e) {
                // console.log(e);
            }

        });



    };
    function tongzhiCk(data) {
        //分页操作
        var page = 0;
        if ("front" === data.signal) {
            if (1 === _tongzhi.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有上一页',
                    time: 2000
                });
            } else {
                page = _tongzhi.current - 1;
            }
        }
        if ("behind" === data.signal) {
            if (_tongzhi.page === _tongzhi.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有下一页',
                    time: 2000
                });
            } else {
                page = _tongzhi.current + 1;
            }
        }
        if ("random" === data.signal) {
            page = data.page;
        }
        if (page === 0) {
            return;
        }
        //请求分页列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                category: "tongzhi",
                page: page,
                count: COUNT,
                total: _tongzhi.total
            },
            crossDomain: true,
            success: function (dat) {
                // console.log(dat)
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //渲染类别标题
                $("#title").html("公告")
                //渲染列表
                $.each(dat.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数

                newPage = parseInt(dat.total / COUNT);
                mod = dat.total % COUNT;
                if (mod != 0) {
                    newPage += 1;
                };
                //初始化公告类别当前分页信息
                _tongzhi.page = newPage;
                switch (dat.msg) {
                    case "0":
                        //删除了上一页的内容
                        _tongzhi.current = newPage;
                        break;
                    case "1":
                        //最后一页
                        _tongzhi.current = newPage;
                        break;
                    case "2":
                        //还有余量

                        if (data.signal === 'front') {
                            if (_tongzhi.current <= newPage) {
                                _tongzhi.current -= 1;
                            } else {
                                _tongzhi.current = newPage;
                            }
                        }
                        if (data.signal === 'behind') {

                            if (_tongzhi.current < newPage) {
                                _tongzhi.current += 1;
                            } else {
                                _tongzhi.current = newPage;
                            }

                        }
                        if (data.signal === 'random') {
                            if (data.page <= newPage) {
                                _tongzhi.current = parseInt(data.page);
                            } else {
                                _tongzhi.current = newPage;
                            }
                        }

                        break;

                };
                _tongzhi.total = parseInt(dat.total);
                clearCategory(CATEGORY.tongzhi);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _tongzhi.page; i++) {
                    if (i == _tongzhi.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    tongzhiCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    tongzhiCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    tongzhiCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })
            },
            error: function (e) {
                // console.log(e);
            }

        });



    };
    function jiangchengCk(data) {
        //分页操作
        var page = 0;
        if ("front" === data.signal) {
            if (1 === _jiangcheng.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有上一页',
                    time: 2000
                });
            } else {
                page = _jiangcheng.current - 1;
            }
        }
        if ("behind" === data.signal) {
            if (_jiangcheng.page === _jiangcheng.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有下一页',
                    time: 2000
                });
            } else {
                page = _jiangcheng.current + 1;
            }
        }
        if ("random" === data.signal) {
            page = data.page;
        }
        if (page === 0) {
            return;
        }
        //请求分页列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                category: "jiangcheng",
                page: page,
                count: COUNT,
                total: _jiangcheng.total
            },
            crossDomain: true,
            success: function (dat) {
                // console.log(dat)
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //渲染类别标题
                $("#title").html("公告")
                //渲染列表
                $.each(dat.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数

                newPage = parseInt(dat.total / COUNT);
                mod = dat.total % COUNT;
                if (mod != 0) {
                    newPage += 1;
                };
                //初始化公告类别当前分页信息
                _jiangcheng.page = newPage;
                switch (dat.msg) {
                    case "0":
                        //删除了上一页的内容
                        _jiangcheng.current = newPage;
                        break;
                    case "1":
                        //最后一页
                        _jiangcheng.current = newPage;
                        break;
                    case "2":
                        //还有余量

                        if (data.signal === 'front') {
                            if (_jiangcheng.current <= newPage) {
                                _jiangcheng.current -= 1;
                            } else {
                                _jiangcheng.current = newPage;
                            }
                        }
                        if (data.signal === 'behind') {

                            if (_jiangcheng.current < newPage) {
                                _jiangcheng.current += 1;
                            } else {
                                _jiangcheng.current = newPage;
                            }

                        }
                        if (data.signal === 'random') {
                            if (data.page <= newPage) {
                                _jiangcheng.current = parseInt(data.page);
                            } else {
                                _jiangcheng.current = newPage;
                            }
                        }

                        break;

                };
                _jiangcheng.total = parseInt(dat.total);
                clearCategory(CATEGORY.jiangcheng);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _jiangcheng.page; i++) {
                    if (i == _jiangcheng.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    jiangchengCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    jiangchengCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    jiangchengCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })
            },
            error: function (e) {
                // console.log(e);
            }

        });



    };
    function xinwenCk(data) {
        //分页操作
        var page = 0;
        if ("front" === data.signal) {
            if (1 === _xinwen.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有上一页',
                    time: 2000
                });
            } else {
                page = _xinwen.current - 1;
            }
        }
        if ("behind" === data.signal) {
            if (_xinwen.page === _xinwen.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有下一页',
                    time: 2000
                });
            } else {
                page = _xinwen.current + 1;
            }
        }
        if ("random" === data.signal) {
            page = data.page;
        }
        if (page === 0) {
            return;
        }
        //请求分页列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                category: "xinwen",
                page: page,
                count: COUNT,
                total: _xinwen.total
            },
            crossDomain: true,
            success: function (dat) {
                // console.log(dat)
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //渲染类别标题
                $("#title").html("公告")
                //渲染列表
                $.each(dat.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数

                newPage = parseInt(dat.total / COUNT);
                mod = dat.total % COUNT;
                if (mod != 0) {
                    newPage += 1;
                };
                //初始化公告类别当前分页信息
                _xinwen.page = newPage;
                switch (dat.msg) {
                    case "0":
                        //删除了上一页的内容
                        _xinwen.current = newPage;
                        break;
                    case "1":
                        //最后一页
                        _xinwen.current = newPage;
                        break;
                    case "2":
                        //还有余量

                        if (data.signal === 'front') {
                            if (_xinwen.current <= newPage) {
                                _xinwen.current -= 1;
                            } else {
                                _xinwen.current = newPage;
                            }
                        }
                        if (data.signal === 'behind') {

                            if (_xinwen.current < newPage) {
                                _xinwen.current += 1;
                            } else {
                                _xinwen.current = newPage;
                            }

                        }
                        if (data.signal === 'random') {
                            if (data.page <= newPage) {
                                _xinwen.current = parseInt(data.page);
                            } else {
                                _xinwen.current = newPage;
                            }
                        }

                        break;

                };
                _xinwen.total = parseInt(dat.total);
                clearCategory(CATEGORY.xinwen);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _xinwen.page; i++) {
                    if (i == _xinwen.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    xinwenCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    xinwenCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    xinwenCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })
            },
            error: function (e) {
                // console.log(e);
            }

        });



    };
    function caozuoCk(data) {
        //分页操作
        var page = 0;
        if ("front" === data.signal) {
            if (1 === _caozuo.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有上一页',
                    time: 2000
                });
            } else {
                page = _caozuo.current - 1;
            }
        }
        if ("behind" === data.signal) {
            if (_caozuo.page === _caozuo.current) {
                layer.open({
                    title: '错误提示框',
                    content: '没有下一页',
                    time: 2000
                });
            } else {
                page = _caozuo.current + 1;
            }
        }
        if ("random" === data.signal) {
            page = data.page;
        }
        if (page === 0) {
            return;
        }
        //请求分页列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                category: "caozuo",
                page: page,
                count: COUNT,
                total: _caozuo.total
            },
            crossDomain: true,
            success: function (dat) {
                // console.log(dat)
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //渲染类别标题
                $("#title").html("操作指南")
                //渲染列表
                $.each(dat.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数

                newPage = parseInt(dat.total / COUNT);
                mod = dat.total % COUNT;
                if (mod != 0) {
                    newPage += 1;
                };
                //初始化公告类别当前分页信息
                _caozuo.page = newPage;
                switch (dat.msg) {
                    case "0":
                        //删除了上一页的内容
                        _caozuo.current = newPage;
                        break;
                    case "1":
                        //最后一页
                        _caozuo.current = newPage;
                        break;
                    case "2":
                        //还有余量

                        if (data.signal === 'front') {
                            if (_caozuo.current <= newPage) {
                                _caozuo.current -= 1;
                            } else {
                                _caozuo.current = newPage;
                            }
                        }
                        if (data.signal === 'behind') {

                            if (_caozuo.current < newPage) {
                                _caozuo.current += 1;
                            } else {
                                _caozuo.current = newPage;
                            }

                        }
                        if (data.signal === 'random') {
                            if (data.page <= newPage) {
                                _caozuo.current = parseInt(data.page);
                            } else {
                                _caozuo.current = newPage;
                            }
                        }

                        break;

                };
                _caozuo.total = parseInt(dat.total);
                clearCategory(CATEGORY.caozuo);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _caozuo.page; i++) {
                    if (i == _caozuo.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    caozuoCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    caozuoCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    caozuoCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })
            },
            error: function (e) {
                // console.log(e);
            }

        });



    };
    //返回列表时根据不同类别调用不同的函数来动态更改分页信息，在retCk中调用
    function gonggaoCkR(data, newPage) {
        _gonggao.page = newPage;

        _gonggao.total = parseInt(data.total);
        clearCategory(CATEGORY.gonggao);

        // 根据条数设置a标签数量渲染分页处toolbar
        pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe603;</i></button><span>';
        for (var i = 1; i <= _gonggao.page; i++) {
            if (i == _gonggao.current) {
                pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

            } else {
                pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
            }
        }
        pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe602;</i></button>';
        $("#page").html(pages);

        // 绑定分页事件
        $("#front").click(function () {
            //渲染上一页
            gonggaoCk({
                signal: "front",
                page: 0
            });
        });
        $("#behind").click(function () {
            //请求下一页
            gonggaoCk({
                signal: "behind",
                page: 0
            });
        });
        $("#page a").click(function () {
            //直接定位到某一页
            gonggaoCk({
                signal: "random",
                page: $(this).html()
            });
        });

    };
    function tongzhiCkR(data, newPage) {
        _tongzhi.page = newPage;

        _tongzhi.total = parseInt(data.total);
        clearCategory(CATEGORY.tongzhi);

        // 根据条数设置a标签数量渲染分页处toolbar
        pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe603;</i></button><span>';
        for (var i = 1; i <= _tongzhi.page; i++) {
            if (i == _tongzhi.current) {
                pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

            } else {
                pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
            }
        }
        pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe602;</i></button>';
        $("#page").html(pages);

        // 绑定分页事件
        $("#front").click(function () {
            //渲染上一页
            tongzhiCk({
                signal: "front",
                page: 0
            });
        });
        $("#behind").click(function () {
            //请求下一页
            tongzhiCk({
                signal: "behind",
                page: 0
            });
        });
        $("#page a").click(function () {
            //直接定位到某一页
            tongzhiCk({
                signal: "random",
                page: $(this).html()
            });
        });

    };
    function jiangchengCkR(data, newPage) {
        _jiangcheng.page = newPage;

        _jiangcheng.total = parseInt(data.total);
        clearCategory(CATEGORY.jiangcheng);

        // 根据条数设置a标签数量渲染分页处toolbar
        pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe603;</i></button><span>';
        for (var i = 1; i <= _jiangcheng.page; i++) {
            if (i == _jiangcheng.current) {
                pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

            } else {
                pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
            }
        }
        pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe602;</i></button>';
        $("#page").html(pages);

        // 绑定分页事件
        $("#front").click(function () {
            //渲染上一页
            jiangchengCk({
                signal: "front",
                page: 0
            });
        });
        $("#behind").click(function () {
            //请求下一页
            jiangchengCk({
                signal: "behind",
                page: 0
            });
        });
        $("#page a").click(function () {
            //直接定位到某一页
            jiangchengCk({
                signal: "random",
                page: $(this).html()
            });
        });

    };
    function xinwenCkR(data, newPage) {
        _xinwen.page = newPage;

        _xinwen.total = parseInt(data.total);
        clearCategory(CATEGORY.xinwen);

        // 根据条数设置a标签数量渲染分页处toolbar
        pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe603;</i></button><span>';
        for (var i = 1; i <= _xinwen.page; i++) {
            if (i == _xinwen.current) {
                pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

            } else {
                pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
            }
        }
        pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe602;</i></button>';
        $("#page").html(pages);

        // 绑定分页事件
        $("#front").click(function () {
            //渲染上一页
            xinwenCk({
                signal: "front",
                page: 0
            });
        });
        $("#behind").click(function () {
            //请求下一页
            xinwenCk({
                signal: "behind",
                page: 0
            });
        });
        $("#page a").click(function () {
            //直接定位到某一页
            xinwenCk({
                signal: "random",
                page: $(this).html()
            });
        });

    };
    function caozuoCkR(data, newPage) {
        _caozuo.page = newPage;

        _caozuo.total = parseInt(data.total);
        clearCategory(CATEGORY.caozuo);

        // 根据条数设置a标签数量渲染分页处toolbar
        pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe603;</i></button><span>';
        for (var i = 1; i <= _caozuo.page; i++) {
            if (i == _caozuo.current) {
                pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

            } else {
                pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
            }
        }
        pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
            + '<i class="layui-icon">&#xe602;</i></button>';
        $("#page").html(pages);

        // 绑定分页事件
        $("#front").click(function () {
            //渲染上一页
            caozuoCk({
                signal: "front",
                page: 0
            });
        });
        $("#behind").click(function () {
            //请求下一页
            caozuoCk({
                signal: "behind",
                page: 0
            });
        });
        $("#page a").click(function () {
            //直接定位到某一页
            caozuoCk({
                signal: "random",
                page: $(this).html()
            });
        });

    };
    function retCk(data) {
        var curr;
        var cate;
        switch (data.category) {
            case 1:
                curr = _gonggao;
                cate = 'gonggao';
                break;
            case 2:
                curr = _tongzhi;
                cate = 'tongzhi';
                break;
            case 3:
                curr = _jiangcheng;
                cate = 'jiangcheng';
                break;
            case 4:
                curr = _xinwen;
                cate = 'xinwen';
                break;
            case 5:
                curr = _caozuo;
                cate = 'caozuo';
                break;
        };
        // console.log(curr + cate);
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                category: cate,
                count: COUNT,
                page: curr.current,
                total: 0
            },
            success: function (dat) {
                //拼接内容，绑定事件
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //总条数、消息码
                // console.log(data)
                //渲染类别标题

                $("#title").html("公告")
                //渲染列表
                $.each(dat.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数
                newPage = parseInt(dat.total / COUNT);
                mod = dat.total % COUNT;
                // console.log(newPage);
                // console.log(mod);
                // console.log(data.total);
                // console.log(COUNT);
                if (mod != 0) {
                    newPage += 1;
                };
                //data 为传入的结果，dat为请求返回的结果
                switch (data.category) {
                    case 1:
                        gonggaoCkR(dat, newPage);
                        break;
                    case 2:
                        tongzhiCkR(dat, newPage);
                        break;
                    case 3:
                        jiangchengCkR(dat, newPage);
                        break;
                    case 4:
                        xinwenCkR(dat, newPage);
                        break;
                    case 5:
                        caozuoCkR(dat, newPage);
                        break;
                };


            },
            error: function (e) {

            }
        });



    };


    //点击公告
    $("#gonggao").click(function () {

        //切换图片
        $(this).attr("src", "./images/gonggao_b.jpg");
        $.each($(this).siblings(), function (i, img) {
            switch (img.id) {
                case "tongzhi":
                    img.src = "./images/tongzhi_a.jpg";
                    break;
                case "jiangcheng":
                    img.src = "./images/jiangcheng_a.jpg";
                    break;
                case "xinwen":
                    img.src = "./images/xinwen_a.jpg";
                    break;
                case "caozuo":
                    img.src = "./images/caozuo_a.jpg";
                    break;
                default:
                    break;
            }

        });


        //获取公告列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                //类别、条数、页数,10条，第一页
                category: 'gonggao',
                count: COUNT,
                page: 1,
                total: 0
            },
            crossDomain: true,
            success: function (data) {
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //总条数、消息码
                // console.log(data)
                //渲染类别标题
                $("#title").html("公告")
                //渲染列表
                $.each(data.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>"
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数
                newPage = parseInt(data.total / COUNT);
                mod = data.total % COUNT;
                // console.log(newPage);
                // console.log(mod);
                // console.log(data.total);
                // console.log(COUNT);
                if (mod != 0) {
                    newPage += 1;
                };
                // if (page > newPage) {
                //     //渲染最后一条
                //     _gonggao.page = newPage;
                //     _gonggao.current = newPage;
                //     _gonggao.total = parseInt(data.total);

                // };
                // if (page <= newPage) {
                //     if (_gonggao.current = 0) {
                //         _gonggao.page = newPage;
                //         _gonggao.current = 1;
                //         _gonggao.total = parseInt(data.total);
                //     }else{

                //     }
                // }
                //初始化公告类别当前分页信息
                _gonggao.page = newPage;
                _gonggao.current = 1;
                _gonggao.total = parseInt(data.total);
                clearCategory(CATEGORY.gonggao);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _gonggao.page; i++) {
                    if (i == _gonggao.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    gonggaoCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    gonggaoCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    gonggaoCk({
                        signal: "random",
                        page: $(this).html()
                    });
                });


            },
            error: function (e) {
                // console.log(e)
            }


        });





    });

    //点击通知
    $("#tongzhi").click(function () {

        $(this).attr("src", "./images/tongzhi_b.jpg");
        $.each($(this).siblings(), function (i, img) {
            switch (img.id) {

                case "gonggao":
                    img.src = "./images/gonggao_a.jpg";
                    break;

                case "jiangcheng":
                    img.src = "./images/jiangcheng_a.jpg";
                    break;
                case "xinwen":
                    img.src = "./images/xinwen_a.jpg";
                    break;
                case "caozuo":
                    img.src = "./images/caozuo_a.jpg";
                    break;
                default:
                    break;
            }
        });

        //获取公告列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                //类别、条数、页数,10条，第一页
                category: 'tongzhi',
                count: COUNT,
                page: 1,
                total: 0
            },
            crossDomain: true,
            success: function (data) {
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //总条数、消息码
                // console.log(data)
                //渲染类别标题
                $("#title").html("通知")
                //渲染列表
                $.each(data.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数
                newPage = parseInt(data.total / COUNT);
                mod = data.total % COUNT;
                // console.log(newPage);
                // console.log(mod);
                // console.log(data.total);
                // console.log(COUNT);
                if (mod != 0) {
                    newPage += 1;
                };
                // if (page > newPage) {
                //     //渲染最后一条
                //     _gonggao.page = newPage;
                //     _gonggao.current = newPage;
                //     _gonggao.total = parseInt(data.total);

                // };
                // if (page <= newPage) {
                //     if (_gonggao.current = 0) {
                //         _gonggao.page = newPage;
                //         _gonggao.current = 1;
                //         _gonggao.total = parseInt(data.total);
                //     }else{

                //     }
                // }
                //初始化公告类别当前分页信息
                _tongzhi.page = newPage;
                _tongzhi.current = 1;
                _tongzhi.total = parseInt(data.total);
                clearCategory(CATEGORY.tongzhi);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _tongzhi.page; i++) {
                    if (i == _tongzhi.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    tongzhiCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    tongzhiCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    tongzhiCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })


            },
            error: function (e) {
                // console.log(e)
            }


        });






    });

    //点击奖惩
    $("#jiangcheng").click(function () {

        $(this).attr("src", "./images/jiangcheng_b.jpg");
        $.each($(this).siblings(), function (i, img) {
            switch (img.id) {

                case "gonggao":
                    img.src = "./images/gonggao_a.jpg";
                    break;

                case "tongzhi":
                    img.src = "./images/tongzhi_a.jpg";
                    break;
                case "xinwen":
                    img.src = "./images/xinwen_a.jpg";
                    break;
                case "caozuo":
                    img.src = "./images/caozuo_a.jpg";
                    break;
                default:
                    break;
            }
        });
        //获取公告列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                //类别、条数、页数,10条，第一页
                category: 'jiangcheng',
                count: COUNT,
                page: 1,
                total: 0
            },
            crossDomain: true,
            success: function (data) {
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //总条数、消息码
                // console.log(data)
                //渲染类别标题
                $("#title").html("奖惩")
                //渲染列表
                $.each(data.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数
                newPage = parseInt(data.total / COUNT);
                mod = data.total % COUNT;
                // console.log(newPage);
                // console.log(mod);
                // console.log(data.total);
                // console.log(COUNT);
                if (mod != 0) {
                    newPage += 1;
                };
                // if (page > newPage) {
                //     //渲染最后一条
                //     _gonggao.page = newPage;
                //     _gonggao.current = newPage;
                //     _gonggao.total = parseInt(data.total);

                // };
                // if (page <= newPage) {
                //     if (_gonggao.current = 0) {
                //         _gonggao.page = newPage;
                //         _gonggao.current = 1;
                //         _gonggao.total = parseInt(data.total);
                //     }else{

                //     }
                // }
                //初始化公告类别当前分页信息
                _jiangcheng.page = newPage;
                _jiangcheng.current = 1;
                _jiangcheng.total = parseInt(data.total);
                clearCategory(CATEGORY.jiangcheng);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _jiangcheng.page; i++) {
                    if (i == _jiangcheng.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    jiangchengCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    jiangchengCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    jiangchengCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })


            },
            error: function (e) {
                // console.log(e)
            }


        });






    });

    //点击新闻
    $("#xinwen").click(function () {

        $(this).attr("src", "./images/xinwen_b.jpg");
        $.each($(this).siblings(), function (i, img) {
            switch (img.id) {

                case "gonggao":
                    img.src = "./images/gonggao_a.jpg";
                    break;

                case "tongzhi":
                    img.src = "./images/tongzhi_a.jpg";
                    break;
                case "caozuo":
                    img.src = "./images/caozuo_a.jpg";
                    break;
                case "jiangcheng":
                    img.src = "./images/jiangcheng_a.jpg";
                    break;
                default:
                    break;
            }
        });

        //获取公告列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                //类别、条数、页数,10条，第一页
                category: 'xinwen',
                count: COUNT,
                page: 1,
                total: 0
            },
            crossDomain: true,
            success: function (data) {
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //总条数、消息码
                // console.log(data)
                //渲染类别标题
                $("#title").html("新闻")
                //渲染列表
                $.each(data.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数
                newPage = parseInt(data.total / COUNT);
                mod = data.total % COUNT;
                // console.log(newPage);
                // console.log(mod);
                // console.log(data.total);
                // console.log(COUNT);
                if (mod != 0) {
                    newPage += 1;
                };
                // if (page > newPage) {
                //     //渲染最后一条
                //     _gonggao.page = newPage;
                //     _gonggao.current = newPage;
                //     _gonggao.total = parseInt(data.total);

                // };
                // if (page <= newPage) {
                //     if (_gonggao.current = 0) {
                //         _gonggao.page = newPage;
                //         _gonggao.current = 1;
                //         _gonggao.total = parseInt(data.total);
                //     }else{

                //     }
                // }
                //初始化公告类别当前分页信息
                _xinwen.page = newPage;
                _xinwen.current = 1;
                _xinwen.total = parseInt(data.total);
                clearCategory(CATEGORY.xinwen);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _xinwen.page; i++) {
                    if (i == _xinwen.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    xinwenCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    xinwenCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    xinwenCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })


            },
            error: function (e) {
                // console.log(e)
            }


        });



    });

    //点击操作
    $("#caozuo").click(function () {

        $(this).attr("src", "./images/caozuo_b.jpg");
        $.each($(this).siblings(), function (i, img) {
            switch (img.id) {

                case "gonggao":
                    img.src = "./images/gonggao_a.jpg";
                    break;

                case "tongzhi":
                    img.src = "./images/tongzhi_a.jpg";
                    break;
                case "xinwen":
                    img.src = "./images/xinwen_a.jpg";
                    break;
                case "jiangcheng":
                    img.src = "./images/jiangcheng_a.jpg";
                    break;
                default:
                    break;
            }
        });

        //获取公告列表
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=utf-8",
            url: "http://sapdev.gewei.com:8000/sap/bc/bsp/sap/zwsap_oa_news/handler.do",
            data: {
                //类别、条数、页数,10条，第一页
                category: 'caozuo',
                count: COUNT,
                page: 1,
                total: 0
            },
            crossDomain: true,
            success: function (data) {
                var news_list = '';
                var pages = '';
                var newPage = 0;
                var mod = 0;
                //总条数、消息码
                // console.log(data)
                //渲染类别标题
                $("#title").html("操作指南")
                //渲染列表
                $.each(data.news_list, function (i, news) {
                    news_list += '<div class="r1c2-div3" style = "margin-top:20px"><a href="#" id='
                        + news.news_id + '>'
                        + news.dis_title + '</a><div class="r1c2-div5">' + news.cha_date + '<span> </span>'
                        + news.cha_time + '</div></div><div class="r1c2-div4"></div>';
                })
                // console.log(news_list)
                news_list += "<br/>";
                $("#content").html(news_list);
                // 绑定列表事件
                $("#content .r1c2-div3 a").click(function () {
                    //新闻详细内容的ajax请求
                    contentCk({
                        news_id: $(this).attr("id"),
                        category: 'detail'
                    });

                });

                // 设置全局参数，page count total
                //根据从服务器取得最新toal，计算分页数
                newPage = parseInt(data.total / COUNT);
                mod = data.total % COUNT;
                // console.log(newPage);
                // console.log(mod);
                // console.log(data.total);
                // console.log(COUNT);
                if (mod != 0) {
                    newPage += 1;
                };
                // if (page > newPage) {
                //     //渲染最后一条
                //     _gonggao.page = newPage;
                //     _gonggao.current = newPage;
                //     _gonggao.total = parseInt(data.total);

                // };
                // if (page <= newPage) {
                //     if (_gonggao.current = 0) {
                //         _gonggao.page = newPage;
                //         _gonggao.current = 1;
                //         _gonggao.total = parseInt(data.total);
                //     }else{

                //     }
                // }
                //初始化公告类别当前分页信息
                _caozuo.page = newPage;
                _caozuo.current = 1;
                _caozuo.total = parseInt(data.total);
                clearCategory(CATEGORY.caozuo);

                // 根据条数设置a标签数量渲染分页处toolbar
                pages = '<button id="front" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe603;</i></button><span>';
                for (var i = 1; i <= _caozuo.page; i++) {
                    if (i == _caozuo.current) {
                        pages += '<a href="#" class=" layui-badge layui-bg-red ">' + i + '</a>';

                    } else {
                        pages += '<a href="#" class="layui-badge layui-bg-green">' + i + '</a>';
                    }
                }
                pages += '</span><button id="behind" type="button" class="layui-btn layui-btn-xs">'
                    + '<i class="layui-icon">&#xe602;</i></button>';
                $("#page").html(pages);

                // 绑定分页事件
                $("#front").click(function () {
                    //渲染上一页
                    caozuoCk({
                        signal: "front",
                        page: 0
                    });
                });
                $("#behind").click(function () {
                    //请求下一页
                    caozuoCk({
                        signal: "behind",
                        page: 0
                    });
                });
                $("#page a").click(function () {
                    //直接定位到某一页
                    caozuoCk({
                        signal: "random",
                        page: $(this).html()
                    });
                })


            },
            error: function (e) {
                // console.log(e)
            }


        });



    });






































});//layui.use结束
